<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-wdyBanner-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">名称：</label>
				<div class="col-sm-8">
					<input id="bannerName" name="bannerName" class="form-control" type="text">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">类型：</label>
				<div class="col-sm-8">
					<select name="bannerType" class="form-control m-b" th:with="type=${@dict.getType('wdy_banner_type')}">
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
					</select>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">图片url：</label>
				<div class="col-sm-8">
					<input id="imageUrl" name="imageUrl" class="form-control" type="hidden">
					<input class="form-control" type="file" onchange="sendFile(this)" accept="image/*">
					<img id="image" src="">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">链接url：</label>
				<div class="col-sm-8">
					<input id="linkUrl" name="linkUrl" class="form-control" type="text">
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "system/wdyBanner"
		$("#form-wdyBanner-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-wdyBanner-add').serialize());
	        }
	    }
        // 上传文件
        function sendFile(obj) {
            if(obj.files[0] == null) {
                $.modal.alertWarning("请先选择文件路径");
                return false;
            }
            var data = new FormData();
            data.append("file", obj.files[0]);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    if (result.code == web_status.SUCCESS) {
                        $('#image').attr('src', result.url);
                        $('#imageUrl').val(result.url);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("图片上传失败。");
                }
            });
        }
	</script>
</body>
</html>
